package com.mao.dao.voucher;


import java.util.List;

import org.hibernate.Query;
import org.hibernate.Session;
import org.springframework.stereotype.Component;

import com.mao.dao.BaseDAOHibernate;
import com.mao.model.voucher.ReturnWareHouseVoucher;

@Component("returnWareHousVoucherDao")
public class ReturnWareHouseVoucherDao extends BaseDAOHibernate{
	
	public ReturnWareHouseVoucher saveReturnWareHouseVoucher(ReturnWareHouseVoucher rwv){
		getHibernateTemplate().saveOrUpdate(rwv);
		return rwv;
	}
	
	public String verifiyCanReturn(long proId,long orgId,long whId) {
		Session session = this.getSession();
		String hql = "FROM ProductWareHouseVoucher pwv where pwv.product.id=:pid and pwv.voucher.org.id=:oid and pwv.voucher.wareHouse.id=:whid";
		Query  query = session.createQuery(hql);
		query.setParameter("pid", proId);
		query.setParameter("oid", orgId);
		query.setParameter("whid", whId);
		List result = query.list();
		if(result.size() > 0){
			return "yes";
		}else{
			return "no";
		}
	}

}
